import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { MenuService } from './menu.service';
import { CreateMenuDto, UpdateMenuDto, PaginationDto } from '@schemas';
import { menuNormalize as norm } from '../../normalize'; // 路径、标签、参数等

@Controller(norm.path)
@ApiTags(norm.tag)
@ApiBearerAuth()
export class MenuController {
  constructor(private readonly menuService: MenuService) {}

  @Post(norm.create.path)
  @ApiOperation({ summary: norm.create.tag })
  create(@Body() createMenuDto: CreateMenuDto) {
    return this.menuService.create(createMenuDto);
  }

  @Post(norm.page.path)
  @ApiOperation({ summary: norm.page.tag })
  pageQuery(@Body() dto?: PaginationDto) {
    return this.menuService.pageQuery(dto);
  }

  @Post(norm.listByIds.path)
  @ApiOperation({ summary: norm.listByIds.tag })
  findListByIds(@Body() ids: string[]) {
    return this.menuService.findListByIds(ids);
  }

  @Get(norm.list.path)
  @ApiOperation({ summary: norm.list.tag })
  findAll() {
    return this.menuService.findAll();
  }

  @Get(norm.detail.path)
  @ApiOperation({ summary: norm.detail.tag })
  findOne(@Param(norm.detail.arg) id: string) {
    return this.menuService.findOne(id);
  }

  @Get('ids')
  @ApiOperation({ summary: '查询所有菜单ID' })
  findIds() {
    return this.menuService.findIds();
  }

  @Patch(norm.update.path)
  @ApiOperation({ summary: norm.update.tag })
  update(
    @Param(norm.update.arg) id: string,
    @Body() updateMenuDto: UpdateMenuDto
  ) {
    return this.menuService.update(id, updateMenuDto);
  }

  @Delete(norm.delete.path)
  @ApiOperation({ summary: norm.delete.tag })
  remove(@Param(norm.delete.arg) id: string) {
    return this.menuService.remove(id);
  }
}
